Skip to content

Fix SystemState_Query atomic load operating on wrong address#3302

Merged
josesimoes merged 2 commits intoadd-pico-chibiosfrom
copilot/sub-pr-3301
Apr 13, 2026
Merged

Fix SystemState_Query atomic load operating on wrong address#3302
josesimoes merged 2 commits intoadd-pico-chibiosfrom
copilot/sub-pr-3301

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

SystemState_Query() on non-Cortex-M0/M0+ targets was atomically loading the local state parameter (an enum index) instead of SystemStates[state], effectively checking whether the state enum value itself was non-zero rather than whether the state was active. This silently broke all system state queries on M3/M4/M7 and similar cores.

Change

  • src/HAL/nanoHAL_SystemEvents.c: Fix the __atomic_load_n target in the #else branch of SystemState_Query():
// Before — loads the enum index, not the state counter
return __atomic_load_n(&state, __ATOMIC_RELAXED) ? true : false;

// After — correctly loads the state counter
return (__atomic_load_n(&SystemStates[state], __ATOMIC_RELAXED) > 0) ? true : false;

This aligns SystemState_Query() with the atomic patterns already used in SystemState_Set() and SystemState_Clear().

…of state parameter

Agent-Logs-Url: https://github.com/nanoframework/nf-interpreter/sessions/0984bdaf-14ad-41c5-9f9e-2cae232dc3a8

Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback to base PR on main branch for Raspberry PICO support Fix SystemState_Query atomic load operating on wrong address Apr 13, 2026
Copilot AI requested a review from josesimoes April 13, 2026 11:27
@josesimoes josesimoes marked this pull request as ready for review April 13, 2026 11:27
@josesimoes josesimoes added Type: bug Area: Common libs Everything related with common libraries labels Apr 13, 2026
@josesimoes
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 04b12281-d932-4f42-8a88-eec41b20d601

📥 Commits

Reviewing files that changed from the base of the PR and between 2fcc122 and 72750f2.

📒 Files selected for processing (1)
  • src/HAL/nanoHAL_SystemEvents.c

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Fixed system state query logic to correctly evaluate state values, improving internal reliability and correctness of state handling.

Walkthrough

A single change to the SystemState_Query function modifies the non-CM0 code path to atomically load from the SystemStates array and compare the loaded value against zero, instead of performing an atomic load on the state parameter and using the raw returned value directly.

Changes

Cohort / File(s) Summary
Atomic Load Logic
src/HAL/nanoHAL_SystemEvents.c
Modified SystemState_Query function's non-CM0 branch to atomically load SystemStates[state] and check if the value is greater than zero, replacing the previous atomic load on the state parameter. CM0/CMSIS branch unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix: an atomic load operating on the wrong address in SystemState_Query().
Description check ✅ Passed The description is directly related to the changeset, explaining the bug, the fix, and the before/after code comparison.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@josesimoes josesimoes merged commit 6f158c9 into add-pico-chibios Apr 13, 2026
28 checks passed
@josesimoes josesimoes deleted the copilot/sub-pr-3301 branch April 13, 2026 13:45
josesimoes pushed a commit that referenced this pull request Apr 13, 2026
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

(cherry picked from commit 6f158c9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Common libs Everything related with common libraries Type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants